package org.vectrics.common.html;

import java.io.OutputStream;
import java.util.Collection;
import java.util.Iterator;

import org.vectrics.SystemException;
import org.vectrics.domain.Domain;
import org.vectrics.domain.HtmlCssEntry;
import org.vectrics.domain.HtmlFormType;
import org.vectrics.provider.CoreServiceLocator;

public class CssBuilder {

	public CssBuilder() {
		super();
	}


	public void execute(OutputStream outputStream, 
			HtmlFormType formType, Domain domain) {
		
		Collection cssEntries = CoreServiceLocator.getSystemService().findCssEntries(domain, formType);
		Iterator iter = cssEntries.iterator();
		String line = "";
		while (iter.hasNext()) {
			HtmlCssEntry cssEntry = (HtmlCssEntry)iter.next();
			line = cssEntry.getClassName() + " " + cssEntry.getValue() + "\r\n";
			try {
				outputStream.write(line.getBytes());
			} catch (Exception ex) {
				throw new SystemException("IOException writing stream", ex);
			}
		}
	}
	
}
